package apps.sim.http;

import java.io.InputStream;
import java.io.OutputStream;

import apps.sim.Index;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;

public class HttpRourceHandler extends HttpBaseHandler {

	public void execute(HttpExchange exchange) throws Exception {

		final Headers responseHeaders = exchange.getResponseHeaders();
		exchange.sendResponseHeaders(200, 0);
		final String string2 = exchange.getRequestURI().toString();
		final String string = string2.split("src=")[1];
		if (string.contains("png")) {
			responseHeaders.set("Content-Type", "image/png");
		} else if (string.contains("css")) {
			responseHeaders.set("Content-Type", "text/css");
		} else if (string.contains("js")) {
			responseHeaders.set("Content-Type", "text/html");
		}
		final OutputStream responseBody = exchange.getResponseBody();
		final InputStream resourceAsStream = Index.class.getResourceAsStream(string);
		write(responseBody, resourceAsStream);
		responseBody.close();
	}

}
